package mtest2.day2;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo5 {
    public static void main(String[] args) {
        // hashmap
        HashMap<String, String> map1 = new HashMap<>();
        // 添加
        map1.put("name", "tom");
        map1.put("age", "22");

        // 获取
        System.out.println(map1); //{name=tom, age=22}
        System.out.println(map1.get("name")); //tom
        System.out.println(map1.keySet()); // [name, age]
        System.out.println(map1.values()); // [tom, 22]

        Set<String> keys = map1.keySet();
        for (String key : keys) {
            System.out.println("key---" + key + "-----value--" + map1.get(key));
        }

        Set<Map.Entry<String, String>> entries = map1.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            System.out.println(entry.getKey() + "-----------" + entry.getValue());
        }
        /*
        key---name-----value--tom
key---age-----value--22
name-----------tom
age-----------22
         */


    }
}
